<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=\, initial-scale=1.0" />
    <title>Document</title>
  
  </head>
  <body>
    <div id="app">
        <button @click="addArr">新增li</button>
        <ul>
          <li v-for="item in arr" ::key="item">
            {{item}}
          </li>
        </ul>
    </div>
    <script src="./vue.global.js"></script>
    <script>
      const { createApp } = Vue;
      const app = createApp({
        data() {
          return {
            arr: [1,2,3,4]
          };
        },
        methods: {
          addArr(){
            this.arr.push(this.arr.length+1);
          }
        },
        watch: {
          arr: {
            handler(val){
              const oul = document.querySelector('ul');
              console.log(oul.children);
            },
            deep: true,
            // 侦听器 由 默认 数据修改后立即触发，改为 数据修改后 视图异步刷新完成后再触发
            flush: 'post'
          }
        }
      });
      app.mount("#app");
    </script>
  </body>
</html>
